﻿using System;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using WMSABL;
using ElectronicWMSA.Comm.ClassFiles;

namespace ElectronicWMSA.SY.SystemDocking
{
    public partial class PickingList_ManageFrm : Form
    {
        private string strWhere = "";
        public PickingList_ManageFrm()
        {
            InitializeComponent();
        }

        private void PickingList_ManageFrm_Load(object sender, EventArgs e)
        {

            this.page1.PageCurrent = 1;
            this.page1.PageSize = 50;
            this.comboBox1.SelectedIndex = 1;
            this.page1.Bind();
        }
        private int DBindData()
        {
            ElectronicWMSA.Comm.Forms.MsControls.PageData pageData = new ElectronicWMSA.Comm.Forms.MsControls.PageData();
            pageData.TableName = "PD_PickingList";
            pageData.PrimaryKey = "NID";
            pageData.OrderStr = "NID";
            pageData.PageIndex = this.page1.PageCurrent;
            pageData.PageSize = this.page1.PageSize;
            pageData.QueryCondition = strWhere;
            pageData.QueryFieldName = "*";

            this.page1.bindingSource.DataSource = pageData.QueryDataTable().Tables[0];
            this.page1.bindingNavigator.BindingSource = page1.bindingSource;
            this.dataGridViewUserList.AutoGenerateColumns = false;
            this.dataGridViewUserList.DataSource = this.page1.bindingSource;
            this.dataGridViewUserList.ClearSelection();
            this.dataGridViewUserList.CurrentCell = null;
            return pageData.TotalCount;
        }
        private int pageControlU_EventPaging(ElectronicWMSA.Comm.Forms.MsControls.EventPagingArg e)
        {
            return DBindData();
        }
        private void dataGridViewUserList_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            SolidBrush b = new SolidBrush(dataGridViewUserList.RowHeadersDefaultCellStyle.ForeColor);
            e.Graphics.DrawString((e.RowIndex + 1).ToString(System.Globalization.CultureInfo.CurrentUICulture), dataGridViewUserList.DefaultCellStyle.Font, b, e.RowBounds.Location.X + 20, e.RowBounds.Location.Y + 4);
        }
        private void btnUserSearch_Click(object sender, EventArgs e)
        {
            if (!SystemVariable.VaildationPermission("查询")) return;
            this.DBindComboxUserName();
            strWhere = "";
            string statTime = dtpTimeStart.Value.ToString("yyyy/MM/dd " + " 00:00:00");
            string EndTime = dtpTimeEnd.Value.ToString("yyyy/MM/dd HH:mm:ss");
            this.strWhere += " CreatTime BETWEEN '" + statTime + "'  AND '" + EndTime + "'";
            if (txtPickingNuber.Text.Trim() != "")
                this.strWhere += " AND PickNO='" + txtPickingNuber.Text.Trim() + "' ";
            if (comboBox1.Text.Trim() != "--请选择--" && comboBox1.Text.Trim() != "")
                this.strWhere += " AND Stauts='" + comboBox1.Text.Trim() + "' ";
            if (comboBox2.Text.Trim() != "--请选择--" && comboBox2.Text.Trim() != "")
                this.strWhere += " AND UserName='" + comboBox2.Text.Trim() + "' ";
            this.page1.Bind();
        }
        PublicDataSet bll_PublicDataSet = new PublicDataSet();
        public void DBindComboxUserName()
        {
            DataSet ds = new DataSet();
            ds = bll_PublicDataSet.GetDataSet(" SELECT NID,userName FROM dbo.PD_PickingList WHERE PickNO='" + this.txtPickingNuber.Text.Trim() + "' GROUP BY NID,userName ");
            DataTable dt = ds.Tables[0];
            DataRow dr = dt.NewRow();
            dr["NID"] = "0";
            dr["userName"] = "--请选择--";
            dt.Rows.InsertAt(dr, 0);
            this.comboBox2.DataSource = dt;
            this.comboBox2.ValueMember = "NID";
            this.comboBox2.DisplayMember = "userName";
        }
        private void linkLabelClose_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Main._Main.CloseTabPages();
        }
        private void linkLabellinkLabelCloseAll_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Main._Main.CloseAllTabPages();
        }
        private void linkLabelCloseElse_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Main._Main.CloseTabPageElse();
        }

    }
}
